home *** CD-ROM | disk | FTP | other *** search
- program MailBob;
- {$R MAILBOB.DFM}
- {$I-,O+}
- uses
- Forms, Extctrls, SysUtils, Classes, DrBobPop, DrBobEml;
-
- type
- TMailBox = class(TForm)
- Timer: TTimer;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure TimerTimer(Sender: TObject);
- private
- From,MailTo,Subject,Date: ShortString;
- Lines: TStringList;
- f: Text;
- end;
-
- procedure TMailBox.FormCreate;
- begin
- ChDir('..');
- ChDir('RobotBob');
- System.Assign(output,'mailbob.html');
- Reset(output);
- if IOResult = 0 then Append(output)
- else Rewrite(output);
- writeln('<HTML>');
- writeln('<BODY BACKGROUND="/gif/back.gif">');
- writeln('<HEAD>');
- writeln('<TITLE>RobotBob/Mail</TITLE>');
- writeln('</HEAD>');
- writeln('<FONT FACE="Comic Sans MS"COLOR=000077>');
- writeln('<H1>RobotBob/Mail v1.0</H1>');
- writeln('</FONT>');
- writeln('<PRE>');
- writeln('MailBob initiated at: ',DateTimeToStr(Now));
- System.Close(output);
- Timer.Enabled := True
- end {FormCreate};
-
- procedure TMailBox.FormDestroy;
- begin
- System.Assign(output,'mailbob.html');
- Append(output);
- writeln;
- writeln('MailBob closing down: ',DateTimeToStr(Now));
- writeln('</BODY>');
- writeln('</HTML>');
- System.Close(output)
- end {FormDestroy};
-
- procedure TMailBox.TimerTimer;
- var
- i,j,k: Integer;
- begin
- System.Assign(output,'mailbob.html');
- Append(output);
- writeln;
- writeln('MailBob waking up at: ',DateTimeToStr(Now));
- try
- with TBPOP3.Create(nil) do
- try
- MailServer := 'pop3.server.com';
- User := 'drbob';
- Password := '********';
- ReadMail;
- writeln(Messages:2,' messages waiting...');
- Lines := TStringList.Create;
- for i:=0 to Pred(Messages) do
- begin
- System.Assign(f,'mailbox');
- Rewrite(f);
- writeln(f,Message[i]);
- System.Close(f);
- Lines.LoadFromFile('mailbox');
- k := 0;
- while (k < Lines.Count) and (Lines[k] <> '') do Inc(k);
- for j:=Pred(k) downto 0 do
- begin
- if (Pos('From: ',Lines[j]) <> 1) and
- (Pos('To: ',Lines[j]) <> 1) and
- (Pos('Subject: ',Lines[j]) <> 1) and
- (Pos('Date: ',Lines[j]) <> 1) then Lines.Delete(j)
- else
- begin
- if Pos('From: ',Lines[j]) = 1 then
- From := Copy(Lines[j],7,255)
- else
- if Pos('To: ',Lines[j]) = 1 then
- MailTo := Copy(Lines[j],4,255)
- else
- if Pos('Subject: ',Lines[j]) = 1 then
- Subject := Copy(Lines[j],10,255)
- else
- Date := Copy(Lines[j],6,255)
- end
- end {headers};
- if Pos('robotbob@drbob42.com',LowerCase(MailTo)) > 0 then
- begin
- with TBSMTP.Create(nil) do
- try
- MailServer := 'smtp.server.com';
- MessageFrom := 'RobotBob';
- MessageTo := 'drbob@drbob.demon.nl';
- MessageSubject := Subject;
- MessageText.Add('Forwarded messages from '+From);
- MessageText.Add('');
- k := 0;
- while (k < Lines.Count) and (Lines[k] <> '') do Inc(k);
- writeln;
- k := 0;
- while (k < Lines.Count) and (Lines[k] <> '') do Inc(k);
- for j:=0 to Pred(k) do writeln(Lines[j]);
- for j:=k to Pred(Lines.Count) do MessageText.Add(Lines[j]);
- MessageText.Add('');
- MessageText.Add('Groetjes,');
- MessageText.Add(' RobotBob - RobotBob@drbob42.com');
- SendMail;
- write('forwarded to ',MessageTo);
- finally
- Free
- end;
- DeleteMessage(i+1);
- writeln(' and deleted from mailhost')
- end
- end
- finally
- Free
- end;
- except
- on E: Exception do
- writeln('<B>Error:</B> ',E.Message)
- end;
- System.Close(output)
- end;
-
- var
- MailBox: TMailBox;
-
- begin
- Application.Initialize;
- Application.ShowMainForm := False;
- Application.CreateForm(TMailBox, MailBox);
- Application.Run
- end.
-